package core;

import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

public class Discipline{
	
	private String m_name;
	private DisciplineType m_type;

	public Discipline(String name, DisciplineType typeOfDiscipline){//(OfDiscipline t){
		m_name = name;
		m_type = typeOfDiscipline;
	}
		
	public String getName(){
		return m_name;
	}
	
	
	public DisciplineType getType(){//OfDiscipline getType(){
		return m_type;
	}

	public void toXml(Node node){
		Element disciplNode = node.createElement(null, "Discipline");
		disciplNode.setAttribute(null, "name", m_name);
		m_type.toXml(disciplNode);
		node.addChild(Node.ELEMENT, disciplNode);        
	}
	
	public static Discipline fromXml(Element elem) throws Throwable{
		try
	    {
			Element rootElem = elem; 
			if (!rootElem.getName().equals("Discipline")){
				rootElem = elem.getElement(null, "Discipline");
			}
			
			String name = rootElem.getAttributeValue(null, "name");
			DisciplineType typeOfDiscipline = DisciplineType.fromXml(rootElem);
			return new Discipline(name, typeOfDiscipline);
	    }
		catch (Exception e) {
			throw e;
		}
	}
}
